import math
import os
import time
import sys

# 将工程目录加入包扫描
currPath = os.path.abspath(os.path.dirname(__file__))
srcPath = os.path.split(currPath)[0]
rootPath = os.path.split(srcPath)[0]
projectPath = os.path.split(rootPath)[0]
sys.path.append(projectPath)

from src.db.CcxDataCenterDb import CcxDataCenter
from src.db.FCDB import FCDB
from src.db.ProdDb import ProdDb
from src.db.CnabsDb import CnabsDb
from src.tasks.abs.SyncAbsDeals import SyncAbsDeals
from src.tasks.abs.SyncAbsTables import SyncAbsTables
from src.tasks.abs.SyncAbsBigData import SyncAbsBigData
from src.utils.CommonUtils import cleanScreen
from src.utils.LogUtils import Logger


# 主函数
def main():
    logger = Logger()
    cleanScreen()

    localDb = ProdDb(logSql=False, autocommit=True)
    cnabsDb = CnabsDb(logSql=False, autocommit=True)

    t = time.perf_counter()

    logger.info("========ABS DATA同步 开始 ========")
    absBigData = SyncAbsBigData(logger=logger, localDb=localDb, absDb=cnabsDb)

    # 证券存量统计
    logger.info("======== 证券存量统计 开始 ========")
    absBigData.__updFullStockData__()

    cast = (time.perf_counter() - t)
    m = math.floor(cast / 60)
    s = cast - m * 60
    logger.info('总耗时: %d分%.3f秒' % (m, s))
    logger.info("========ABS DATA同步 结束 ========")


# 程序入口
if __name__ == "__main__":
    main()
